#include <iostream>
#include <queue>

struct pos
{
	int x, y;
};

int const inf = 1 << 30;
int const maxn = 2000;
int n, m, a, b;
int dis[maxn][maxn];
bool map[maxn][maxn];
bool vis[maxn][maxn];

int const opt[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};

bool inrange(int x, int y)
{
	return (0 <= x && x < n)  && (0 <= y && y < m);
}

int main()
{	
	std::cin >> m >> n >> a >> b;
	for (int i = 0; i < n; i++)	
		for (int j = 0; j < m; j++) {
			char ch;
			std::cin >> ch;
			dis[i][j] = inf;
			map[i][j] = ch == '.';
		}

	std::queue<pos> q;
	dis[0][0] = 0;
	q.push({0, 0});
	vis[0][0] = true;
	int ans = -1;
	while (!q.empty()) {
		pos now = q.front(); q.pop();
		if (now.x == n - 1 && now.y == m - 1) {
			ans = dis[now.x][now.y];
			break;
		}
		for (int i = 0; i < 4; i++) {
			int px = now.x + opt[i][0], py = now.y + opt[i][1];
			int c = 0;
			if ((now.x&1)^(now.y&1)) c = a;
			else		   c = b;
			if (inrange(px, py) && map[px][py]) {
				if (dis[px][py] == -1 || dis[px][py] > dis[now.x][now.y] + c) {
					dis[px][py] = dis[now.x][now.y] + c;
				}
				if (!vis[px][py]) {
					vis[px][py] = true;
					dis[px][py] = dis[now.x][now.y] + c;
					q.push({px, py});
				}
			}
		}
	}
	if (ans == -1)
		std::cout << "IMPOSSIBLE\n";
	else
		std::cout << ans << '\n';
}
